Skip to content

feat: per-trace current_context_size in Langfuse usageDetails - #22

Merged
winjer merged 15 commits into
mainfrom
change/current-context-size
Aug 20, 2026
Merged

feat: per-trace current_context_size in Langfuse usageDetails#22
winjer merged 15 commits into
mainfrom
change/current-context-size

Conversation

@winjer

@winjer winjer commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Adds a current_context_size key to each generation observation's usageDetails, matching the number the OpenCode TUI "Context" panel shows: input + output + reasoning + cache.read + cache.write of the trace's last assistant message with output > 0.

Non-obvious constraints the diff doesn't show:

  • Existing summed usage (input/output/cache keys) is byte-for-byte unchanged; the metric is additive only.
  • For Claude Code traces the formula reduces to the 4-field Anthropic sum (reasoning_tokens absent → 0).
  • reasoning_tokens is carried through the normalised message.usage seam internally but deliberately NOT leaked into usageDetails.
  • Key is omitted (never emitted as 0) when no qualifying assistant step exists, matching the existing omit-don't-zero convention in emit.rs.
  • Pi traces unaffected (no usage block).

Full design/plan history in planflow/archive/2026-08-20-current-context-size/.

@winjer
winjer marked this pull request as ready for review August 20, 2026 09:25
@winjer
winjer merged commit 5c1a0e0 into main Aug 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant